import { Controller, Get, Query } from '@nestjs/common';
import { LogService } from './log.service';
import { RequireLogin, RequirePermission } from 'src/custom.decorator';
import {
  ApiTags,
  ApiOperation,
  ApiBearerAuth,
  ApiQuery,
} from '@nestjs/swagger';

@ApiTags('日志管理')
@ApiBearerAuth()
@Controller('log')
@RequireLogin()
export class LogController {
  constructor(private readonly logService: LogService) {}

  @Get('list')
  @RequirePermission('log:query')
  @ApiOperation({ summary: '获取操作日志列表' })
  @ApiQuery({
    name: 'pageNum',
    description: '页码',
    required: false,
    type: Number,
  })
  @ApiQuery({
    name: 'pageSize',
    description: '每页数量',
    required: false,
    type: Number,
  })
  @ApiQuery({ name: 'username', description: '用户名', required: false })
  @ApiQuery({ name: 'path', description: '请求路径', required: false })
  @ApiQuery({ name: 'method', description: '请求方法', required: false })
  @ApiQuery({ name: 'startTime', description: '开始时间', required: false })
  @ApiQuery({ name: 'endTime', description: '结束时间', required: false })
  async findAll(
    @Query('pageNum') pageNum = 1,
    @Query('pageSize') pageSize = 10,
    @Query('username') username?: string,
    @Query('path') path?: string,
    @Query('method') method?: string,
    @Query('startTime') startTime?: string,
    @Query('endTime') endTime?: string,
  ) {
    return await this.logService.findAll(
      pageNum,
      pageSize,
      username,
      path,
      method,
      startTime,
      endTime,
    );
  }
}
